package com.dscs.controller;

import com.dscs.annotation.PermissionAnnotation;
import com.dscs.domain.Permission;
import com.dscs.domain.Role;
import com.dscs.domain.User;
import com.dscs.service.IUserService;
import com.dscs.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 叶雪娟
 * @date 2019/7/18
 * @RestController ：@RestController 是spring4里的新注解，是@ResponseBody和@Controller的缩写。
 **/
@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    IUserService ius;

    /**
     * 查询所有用户信息
     *
     * @return List<User>
     */
    @GetMapping(value = "/queryAllUser")
    @PermissionAnnotation(value = true)
    public List<User> queryAllUser() {
        return ius.queryAllUser();
    }

    /**
     * 通过用户id列表查询多个用户
     *
     * @return List<User>
     */
    @GetMapping(value = "/queryUserByIds")
    public List<User> queryUserByIds(@RequestParam("ids") String ids) {
        return ius.queryUserByIds(ids);
    }

    /**
     * 查询用户的角色
     *
     * @return List<Role>
     */
    @GetMapping(value = "/queryUserRole")
    public List<Role> queryUserRole(@RequestParam("id") String id) {
        long userId = Integer.valueOf(id);
        return ius.queryUserRole(userId);
    }

    /**
     * 查询用户的权限
     *
     * @return List<Permission>
     */
    public List<Permission> queryUserPermission(@RequestParam("userId") String userId) {
        long id = Integer.valueOf(userId);
        return ius.queryUserPermission(id);
    }

    /**
     * 根据id查询用户
     *
     * @return User
     */
    @GetMapping(value = "/queryUser")
    public User queryUser(@RequestParam("id") String id){
        long i = Integer.valueOf(id);
        return ius.queryUser(i);
    }
    /**
     * 根据id查询用户
     *
     * @return User
     */
    @PostMapping(value = "/insertUser")
    public Msg insertUser(User user){
        return ius.insertUser(user);
    }
    /**
     * 更新用户信息
     *
     * @return User
     */
    @PutMapping(value = "/updateUser")
    public Msg updateUser(User user){
        return ius.updateUser(user);
    }
    /**
     * 删除用户
     *
     * @return User
     */
    @DeleteMapping(value = "/deleteUser")
    public Msg deleteUser(@RequestParam("id") String id){
        long i = Integer.valueOf(id);
        return ius.deleteUser(i);
    }

    @GetMapping(value = "/queryUsersByCondition")
    public List<User> queryUsersByCondition(User user){
        return ius.queryUsersByCondition(user);
    }

    @PutMapping(value = "/updateUserInfo")
    public Msg updateUserInfo(){
        return ius.updateUserInfo();
    }





}
